package xin.exec.executor.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * <pre>
 * 异步服务
 * </pre>
 *
 * @author lixin_ma@outlook.com
 * @version 1.0
 * @since 2019/8/9 19:48
 */
@Service
@Slf4j
public class SimpleAsyncService{

    @Async
    public void task1() throws InterruptedException{
        log.info("start {}", Thread.currentThread().getName());
        Thread.sleep(3000);
        log.info("end {}", Thread.currentThread().getName());
    }

    @Async
    public void task2() throws InterruptedException {
        log.info("start {}", Thread.currentThread().getName());
        Thread.sleep(3000);
        log.info("end {}", Thread.currentThread().getName());
    }

    @Async
    public void task3() throws InterruptedException {
        log.info("start {}", Thread.currentThread().getName());
        Thread.sleep(3000);
        log.info("end {}", Thread.currentThread().getName());
    }


    @Async
    public void task4() throws InterruptedException{
        log.info("start {}", Thread.currentThread().getName());
        Thread.sleep(3000);
        log.info("end {}", Thread.currentThread().getName());
    }

    @Async
    public void task5() throws InterruptedException{
        log.info("start {}", Thread.currentThread().getName());
        Thread.sleep(3000);
        log.info("end {}", Thread.currentThread().getName());
    }

    @Async
    public void testThrow(String p1, String p2, Map<String ,Object> p3) throws InterruptedException{
        log.info("start {}", Thread.currentThread().getName());
        Thread.sleep(3000);
        log.info("end {}", Thread.currentThread().getName());
        throw new  RuntimeException("测试异常处理");
    }
}
